package com.derbysoft.ota.interfaces.ws.hotel;

import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;

import com.derbysoft.ota.application.service.HotelResService;
import com.derbysoft.ota.application.service.StagingService;
import com.derbysoft.ota.application.util.Elements;
import com.derbysoft.ota.domain.server.ServerType;
import com.derbysoft.ota.interfaces.protocol._2009a.HotelResRequestType;
import com.derbysoft.ota.interfaces.protocol._2009a.HotelResResponseType;
import com.derbysoft.ota.interfaces.ws.AbstractEndpoint;

public class HotelResEndpoint extends AbstractEndpoint {

	private HotelResService hotelResService;

	public HotelResEndpoint(ServerType serverType, StagingService stagingService, HotelResService hotelResService) {
		super(serverType, stagingService);
		this.hotelResService = hotelResService;
	}


	@SuppressWarnings("unchecked")
	@Override
	protected Object invokeInternal(Object requestObject) throws Exception {
		JAXBElement<HotelResRequestType> element = (JAXBElement<HotelResRequestType>) requestObject;
		if (serverType.isStaging()) {
			return stagingService.make(element);
		}
		HotelResResponseType response = hotelResService.make(element.getValue());
		return new JAXBElement<HotelResResponseType>(
			new QName(Elements.OTA_NAMESPACE_URI, "OTA_HotelResRS"), 
			HotelResResponseType.class, 
			response
		);
	}

}
